<?php
/*
 * General Functions
 * 
 * Mainly used functions
 * 
 * @author : Jason Meulenhoff
 * @mail : mail@kacangboi.com
 * @web : http://kacangboi.com
 * @copyright : KacangNetworks 2010
 * 
 */

function isLogged()
{
	if (isset($_SESSION['logged']))
		return true;
	else
		header("Location: index.controller.php");
}

function maxConnections()
{
	$database = new databaseManager();
	if($database->countSessions() > CONNECTION_MAX)
		return true;
	else
		return false;
}

function sessionExpired()
{
	if(isset($_SESSION['logged']))
	{
		if(time() > $_SESSION['logged']['valid'])
		{
			logout();
		}
		else
			updateSession();
	}
}

function logout()
{
	$login = new login();
	$login->logout();
}

function updateSession()
{
	$database = new databaseManager();
	$database->updateSession();
}
?>
